﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include "IImplementationUidTreeManager.h"
#include "IUidTree.h"
#include "UniIdentity.h"

namespace gcmp
{
    template<class Parent, class Child>
    class ImplementationUidTreeRegisterHelper
    {
    public:
        ImplementationUidTreeRegisterHelper(const std::wstring& parentInfo, const std::wstring& childInfo)
        {
            IImplementationUidTreeManager* pMgr = IImplementationUidTreeManager::Get();
            DBG_WARN_AND_RETURN_VOID_UNLESS(pMgr, L"Implementation uid tree manager is null.",
                L"GMEP", L"2020-04-13");
            pMgr->CacheParentChildUidRelation(Parent::GetImplementationUid(), Child::GetImplementationUid());
        }

        ~ImplementationUidTreeRegisterHelper()
        {
        }
    };
}

namespace
{
#define _CAT(A, B)   A##B
#define _WSTRING(A)  _CAT(L, #A)
}

#define REGISTER_IMPLEMENTATION_UID_TREE_RELATION(PARENT_CLASS_NAME, CHILD_CLASS_NAME) \
namespace { \
    static gcmp::ImplementationUidTreeRegisterHelper<PARENT_CLASS_NAME, CHILD_CLASS_NAME> \
        s_##PARENT_CLASS_NAME##CHILD_CLASS_NAME##ImplementationUidTreeRegisterHelper( \
        _WSTRING(PARENT_CLASS_NAME), _WSTRING(CHILD_CLASS_NAME)); \
}


